﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<link rel="stylesheet" type="text/css" media="screen" href="css/smoothness/jquery-ui-1.10.3.custom.min.css" />	<!-- jqueryUI CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />							<!-- jqGrid CSS -->
<link rel="stylesheet" type="text/css" media="screen" href="css/selfTemplate.css" />						<!-- 本專案自行定義 CSS -->

<script src="js/jquery-1.9.1.min.js"></script>		<!-- jQuery 核心 -->
<script src="js/grid.locale-tw.js" type="text/javascript"></script>											<!-- jqGrid 語系檔 -->
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>										<!-- jqGrid 核心 -->
<script src="js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->
<script src="js/jquery.cookie.js"></script>																	<!-- 操作cookie用 -->
<script src="js/widgets.js" type="text/javascript"></script>							<!-- jqueryUI 核心 -->

<title>維護Squad所包含的主機</title>

<script type="text/javascript">

function selectSubSys() {
	$("#a_form #subSysId").val( $("select#subsys option:selected").val() );
	
	$("select#env .forRemove").remove();
	$("select#squad .forRemove").remove();
	
	/*	先查詢有那些環境 Select	*/
	var tmp ="";
	$("#fc").val("mappingSquadHost");
	$.post("QueryEnv",$("#a_form").serializeArray(),function(reses) {
		if (reses.length > 0) {
			$.each(reses,function(i, res) {
				tmp = "<option class='forRemove' value='"+res.id+"'>"+res.name+" ("+res.id+")"+"</option>";
				$("#env").append(tmp);
			});	
		}
	});
}

$(document).ready(function() {

	if ($.cookie("userId") == null) {
		alert("請先登入系統");
		location.assign("index.html");
	} else {
		$("#a_form #loginUser").val( $.cookie("userId") );
		$("#a_form #isSU").val( $.cookie("isSU") );
		$("#env").on("change",function(){
			$("#a_form #bssId").val( $("select#bss option:selected").val() );
			$("#a_form #envId").val( $("select#env option:selected").val() );
			$("select#squad .forRemove").remove();
			
			var tmp ="";
			$("#fc").val("mappingSquadHost");
			$.post("QuerySquad",$("#a_form").serializeArray(),function(reses) {
				if (reses.length > 0) {
					$.each(reses,function(i, res) {
						tmp = "<option class='forRemove' value='"+res.id+"'>"+res.name+" ("+res.id+")"+"</option>";
						$("#squad").append(tmp);
					});	
				}
			});
		});
		
		
		$("#squad").on("change",function(){
			jQuery("#grid1").jqGrid('setGridParam',{
				url:"QueryHost",
				datatype: "json",
				postData: {
					bssId: function() { return $("select#bss option:selected").val(); },
					subSysId: function() { return $("select#subsys option:selected").val(); },
					envId: function() { return $("select#env option:selected").val(); },
					squadId: function() { return $("select#squad option:selected").val(); },
					fc: function() { return "mappingSquadHost"; }
				}
			}).jqGrid("setCaption",$("select#subsys option:selected").text()+"， "+$("select#env option:selected").text()+"， "+$("select#squad option:selected").text()+"，所轄主機").trigger('reloadGrid');
			
			$("#grid1").off('click',".jqgrow td input[type='checkbox']");
			$("#grid1").on('click',".jqgrow td input[type='checkbox']", function () {
				$.post("ManipulateMpSquadHost",{ bssId:$("#bss option:selected").val(),subSysId:$("#subsys option:selected").val(),envId:$("#env option:selected").val(),squadId:$("#squad option:selected").val(),ip:$(this).parent().next().text(),port:$(this).parent().next().next().next().text(),currentUser:$.cookie("userId")},function(res) {
				});
			});
		});	
		
		
		
		/*	先查詢有那些子系統供 Select	*/
		var tmp ="";
		$("#fc").val("mappingSquadHost");
		$.post("QuerySubSys",$("#a_form").serializeArray(),function(reses) {
			$.each(reses,function(i, res) {
				tmp = "<option class='forRemove' value='"+res.id+"'>"+res.name+" ("+res.id+")"+"</option>";
				$("#subsys").append(tmp);
			});
		});
		
		
		$("#grid1").jqGrid({
			modal:true,  
			jqModal:true,
		   	colNames:["<input type='checkbox' onclick='checkBox(event)' />","主機IP", "主機名稱","PORT","系統","子系統"],
		   	colModel:[
				{	/*	CheckBox for 勾選	*/
					name:'my_checkbox',
					width:75,
					align:'center',
					edittype:"checkbox",
					formatter: "checkbox",
					sortable: false,
					formatoptions: {disabled:false}
				},
		   		{name:"hostIP",index:"hostIP", edittype:"text"},
		   		{name:"hostName",index:"hostName"},
		   		{name:"port",index:"port"},
		   		{name:"bssId",index:"bssId"},
		   		{name:"subSysId",index:"subSysId"}
		   	],
		   	rowNum: 6,
		   	forceFit: true,
		   	pager: "#pager",
			rownumbers: true,
		   	viewrecords: true,	
			caption: "維護主機"
		});
		jQuery("#grid1").jqGrid("navGrid","#pager",{add:false,edit:false,del:false,search:false,refresh:false});
		initPage("維護資源群組下轄主機");
	}
}).tooltip();
</script>

</head>
<body>
	<div id="header"></div>
	<p>
	<form id="q_form">
		<input type="hidden" id="bssId" name="bssId" />
		
		<input type="hidden" id="envId" name="envId" />
		
		<!-- 用來進行 Update時使用 -->
		<input type="hidden" id="oriHostIP" name="oriHostIP" />
		<input type="hidden" id="oriBssId" name="oriBssId" />
		<input type="hidden" id="oriSubSysId" name="oriSubSysId" />
		<input type="hidden" id="oriPort" name="oriPort" />
		<input type="hidden" id="hostName" name="hostName" />
		
	</form>
	<form id="a_form">
		<input type="hidden" id="fc" name="fc" />
		<input type="hidden" id="bssId" name="bssId" />
		<input type="hidden" id="subSysId" name="subSysId" />
		<input type="hidden" id="envId" name="envId" />
		<input type="hidden" id="loginUser" name="loginUser" />
		<input type="hidden" id="isSU" name="isSU" />
	</form>
	
	
	<br/>
	
<table>
<tr>
<th class="right"><label for="bss">系統：</label></th>
<td><select id="bss">
<option value="MBMS">MBMS</option>
</select></td>
</tr>
<tr>
<th class="right"><label for="subsys">子系統：</label></th>
<td>
	<select id="subsys" onchange="selectSubSys()"><option>--請選擇--</option></select>
</td>
</tr>
<tr>
<th class="right"><label for="env">環境：</label></th>
<td>
	<select id="env"><option>--請選擇--</option></select>
</td>
</tr>
<tr>
<th class="right"><label for="squad">資源群組：</label></th>
<td>
	<select id="squad"><option>--請選擇--</option></select>
</td>
</tr>
</table>

<p>
<hr/>
<p>
<table id="grid1"></table>
<div id="pager"></div>


</body>
</html>